<?php
namespace app\common\model;

use think\Model;

class User extends Model{
    /*
     * 注册
     */
    public function reg($data){
        $data['password'] = md5( $data['password']);
        $result = $this->insert($data);
        return $result;
    }
    /*
     * 登录
     */
    public function login($data){
//        $result = $this->whereOr('username',$data['username'])->whereOr('mobile',$data['username'])->where('password',md5($data['password']))->field('id,username')->find();
        $result = $this->where(array('username|mobile'=>$data['username']))->where('password',md5($data['password']))->field('id,username')->find();
        if($result){
            $utM = new UserToken();
            $usertoken = $utM->setToken($result['id']);
            if($usertoken['code']){
                $result['id'] = $usertoken['data'];
            }
        }
        return $result;
    }


}